package leetcode.easy;

import leetcode.base.TreeNode;

/**
 * ClassName: $101_IsSymmetric
 * Description:
 * date: 2021-11-17 22:44
 *
 * @author liyifan
 */
public class $101_IsSymmetric {
    public boolean isSymmetric(TreeNode root) {
        if (root == null)
            return true;
        return dfs(root.left, root.right);
    }

    boolean dfs(TreeNode left, TreeNode right){
        if (left == null && right == null)
            return true;
        if (left == null || right == null)
            return false;
        if (left.val != right.val)
            return false;
        return dfs(left.right, right.left) && dfs(left.left, right.right);
    }
}
